package com.metagurukul.informer.servlets;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.metagurukul.informer.service.AnswerService;


/**
 * Servlet implementation class ApproveAnswer
 */
@WebServlet("/ApproveAnswer")
public class ApproveAnswer extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ApproveAnswer() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		try {
			int answerId = Integer.parseInt(request.getParameter("id"));
			int questionId = Integer.parseInt(request.getParameter("ques_id"));
			AnswerService ansService = new AnswerService(answerId);
			ansService.approveAnswer();
			String url = "ShowQuestion?id="+questionId;
			request.getRequestDispatcher(url).forward(request, response);
		} catch (SQLException e) {
			response.sendRedirect("Error.jsp");
		}	
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
